import { request } from "@/utils/axios";

import type { ChatMessage, ChatSession } from "@/types/session";
import type { Data } from "@/utils/axios";

export const sessionApi = {
  // 新建会话
  createChat: (roleId: string): Promise<Data<ChatSession>> => {
    return request<ChatSession>(`/session/${roleId}`, "POST");
  },

  // 获取用户所有会话
  getUserChats: (): Promise<Data<ChatSession[]>> => {
    return request<ChatSession[]>("/session/list", "GET");
  },

  // 获取单个会话接口
  getChatById: (id: string): Promise<Data<ChatSession>> => {
    return request<ChatSession>(`/session/${id}`, "GET");
  },

  // 更新会话标题
  updateChatTitle: (chatId: string, title: string): Promise<Data<object>> => {
    return request<object>(`/chat/updateTitle`, "POST", { title, chatId });
  },

  // 删除会话接口
  deleteChatById: (id: string): Promise<Data<object>> => {
    return request<object>(`/chat/deleteChat/${id}`, "GET");
  },

  // 获取该会话的所有历史消息
  getChatHistory: (id: string): Promise<Data<ChatMessage[]>> => {
    return request(`/message/list/${id}`);
  },
};
